//
//  LoginViewController.m
//  bluetooth
//
//  Created by 周季阳 on 15/7/14.
//  Copyright (c) 2015年 switch. All rights reserved.
//

#import "LoginViewController.h"
#import "AppDelegate.h"
#import "MainViewController.h"
#import "LeftViewController.h"
#import "UIViewAdditions.h"
#import "VerifyViewController.h"
@interface LoginViewController ()<UITextFieldDelegate,UIScrollViewDelegate>
{
    UIScrollView *zScrollView;
    UITextField *zPhoneText;
}
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden=YES;

    [self initUI];
   
}
#pragma mark - initUI
-(void)initUI{
    NSLog(@"%2f",self.view.size.height);
    zScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, -20, SCREEN_WIDTH, SCREEN_HEIGHT+20)];
    if (SCREEN_HEIGHT<500) {
        zScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
    }else{
        zScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
    }
    zScrollView.userInteractionEnabled = YES;
    [self.view addSubview:zScrollView];

    
    UIImageView *backImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [backImg setImage:[UIImage imageNamed:@"登陆"]];
    backImg.userInteractionEnabled = YES;
    [zScrollView addSubview:backImg];
    
    UIImageView *textImg = [[UIImageView alloc]initWithFrame:CGRectMake(10, backImg.frame.size.height/2,SCREEN_WIDTH-20, 40)];
    [textImg setImage:[UIImage imageNamed:@"登陆_03"]];
    textImg.userInteractionEnabled = YES;
    [zScrollView addSubview:textImg];
    
    UILabel *textLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 25, 40)];
    textLabel.text = @"+86";
    textLabel.textColor = [UIColor whiteColor];
    textLabel.textAlignment = NSTextAlignmentLeft;
    textLabel.font = [UIFont systemFontOfSize:13];
    [textImg addSubview:textLabel];
    
    zPhoneText = [[UITextField alloc] initWithFrame:CGRectMake(textLabel.right+20, 0 ,textImg.frame.size.width-40-textLabel.size.width , 40)];
    zPhoneText.tag = 1;
    zPhoneText.placeholder = @"请输入手机号码";
    zPhoneText.font = [UIFont systemFontOfSize:13];
    [textImg addSubview:zPhoneText];
    zPhoneText.delegate = self;
    
    UIButton *zBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    zBtn.frame = CGRectMake(10, textImg.bottom+10, SCREEN_WIDTH-20, 37);
    [zBtn setBackgroundImage:[UIImage imageNamed:@"登陆_07"] forState:UIControlStateNormal];
    [zBtn addTarget:self action:@selector(clickZBtn) forControlEvents:UIControlEventTouchUpInside];
    [backImg addSubview:zBtn];
    
    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
    [singleTapGestureRecognizer setNumberOfTapsRequired:1];
    [zScrollView addGestureRecognizer:singleTapGestureRecognizer];


}
#pragma marj - 验证
-(void)clickZBtn{
    //防止同次点击
    //先将未到时间执行前的任务取消。
//    [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(todoSomething:) object:sender];
//    [self performSelector:@selector(todoSomething:) withObject:sender afterDelay:0.2f]
    VerifyViewController *verify = [[VerifyViewController alloc]init];
    [self.navigationController pushViewController:verify animated:YES];
}
#pragma mark - 点击屏幕空白区域
-(void)singleTap{
    [zPhoneText resignFirstResponder];
}

#pragma mark - UItextField Delegate
-(void)textFieldDidBeginEditing:(UITextField *)textField{
    zScrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+100);
    [zScrollView setContentOffset:CGPointMake(0, 100) animated:YES];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    zScrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
    return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
    [textField resignFirstResponder];
    zScrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
